import request from '../../utils/request';

// 联系人信息接口
export interface ContactVO {
  id?: number;
  name: string;
  customerId: number;
  customerName?: string;
  contactNextTime?: Date;
  contactLastTime?: Date;
  ownerUserId: number;
  ownerUserName?: string;
  mobile?: string;
  telephone?: string;
  email?: string;
  post?: string;
  qq?: string;
  wechat?: string;
  sex?: number;
  policyMakers?: boolean;
  master?: boolean;
  remark?: string;
  areaId?: number;
  areaName?: string;
  detailAddress?: string;
  createTime?: Date;
  updateTime?: Date;
}

// 联系人分页查询参数
export interface ContactPageParams {
  pageNo?: number;
  pageSize?: number;
  name?: string;
  mobile?: string;
  customerId?: number;
  ownerUserId?: number;
}

// 联系人 API
export const ContactApi = {
  // 查询联系人分页
  getContactPage: async (params: ContactPageParams) => {
    return await request.get('/crm/contact/page', { params });
  },

  // 查询联系人详情
  getContact: async (id: number) => {
    return await request.get(`/crm/contact/${id}`);
  },

  // 新增联系人
  createContact: async (data: ContactVO) => {
    return await request.post('/crm/contact', data);
  },

  // 修改联系人
  updateContact: async (data: ContactVO) => {
    return await request.put('/crm/contact', data);
  },

  // 删除联系人
  deleteContact: async (id: number) => {
    return await request.delete(`/crm/contact/${id}`);
  },

  // 转移联系人
  transferContact: async (ids: number[], newOwnerUserId: number) => {
    return await request.put('/crm/contact/transfer', { ids, newOwnerUserId });
  },

  // 获取联系人简单列表
  getContactSimpleList: async (customerId?: number) => {
    return await request.get('/crm/contact/simple-list', { params: { customerId } });
  },

  // 导出联系人
  exportContact: async (params: ContactPageParams) => {
    return await request.get('/crm/contact/export', { params, responseType: 'blob' });
  }
};